<template>
  <el-container class="home_container">
    <!-- 头部区域 -->
    <el-header>
      <div>
        <img src="../assets/10.png" alt="" />
        <span>XX后台管理系统</span>
      </div>

      <el-button type="danger" @click="logout" background-color="rgba(244,240,230,1)" > 退出 </el-button></el-header
    >
    <el-container>
      
      <!-- 侧边栏 -->
      <el-aside :width="istogglecollapse ? '64px':'200px' ">
        <div class="toggle-button" @click="togglecollapse">|||</div>
        <el-menu
          background-color="rgba(217,217,243,1)"
          text-color="#000"
          active-text-color="#5353f6"
          unique-opened
          :collapse='istogglecollapse'
          :collapse-transition='false'
          router
          :default-active='activepath'
        >
          <!-- 一级菜单 -->
          <el-submenu :index="item.id + ''" v-for="item in menulist" :key="item.id">
            <!-- 一级菜单模板 -->
            <template slot="title">
              <!-- 图标 -->
              <i :class="icons_obj[item.id]"></i>
              <!-- 文本 -->
              <span>{{item.authName}}</span>
            </template>
            <el-menu-item :index=" '/' + opp.path" v-for="opp in item.children" :key="opp.id" @click="savenavstate('/' + opp.path)">
              <template slot="title">
                <i :class="icons_obj['111']"></i>
                <!-- 文本 -->
                <span>{{opp.authName}}</span>
              </template>
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <!-- 主体 -->
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
  data(){
    return {
      menulist:[],
      icons_obj:{
        '125':'iconfont icon-users',
        '103':'iconfont icon-3702mima',
        '101':'iconfont icon-shangpin',
        '102':'iconfont icon-danju',
        '145':'iconfont icon-tijikongjian',
        '111':'iconfont icon-morentouxiang'
      },
      istogglecollapse:false,
      //被激活的链接地址
      activepath:''
    }
  },
  created() {
    this.gitMenuList(),
    this.activepath = window.sessionStorage.getItem('activepath')
  
  },
  methods: {
    logout() {
      window.sessionStorage.clear()
      this.$router.push('/login')
    },
    async gitMenuList() {
      const { data: res } = await this.$http.get('menus')
      if(res.meta.status !== 200) return this.$message.error(res.meta.msg)
      this.menulist = res.data
    //  console.log( this.menulist)
    },
    togglecollapse(){
      this.istogglecollapse = !this.istogglecollapse
    },
    savenavstate(activepath){
      window.sessionStorage.setItem('activepath',activepath)
      this.activepath = activepath
    }
  },
}
</script>

<style lang='less' scoped>
.iconfont {
  margin-right: 10px;
}

.el-header {
  background-color:rgba(157,211,168,1);
  display: flex;
  justify-content: space-between;
  padding-left: 0;
  align-items: center;
  color: white;
  font-size: 20px;
  > div {
    display: flex;
    align-items: center;
    img {
      height: 60px;
    }
    span {
      margin-left: 15px;
    }
  }
}
.el-aside {
  background-color: rgba(217,217,243,1);
  .el-menu {
    border-right: none;
  }
  .toggle-button {
    background-color:rgb(201, 201, 221);
    color: rgb(36, 35, 35);
    text-align: center;
    line-height: 24px;
    letter-spacing: 0.2em;
    cursor: pointer;
  }
}
.el-main {
  background-color:rgba(244,240,230,1);
}
.home_container {
  height: 100%;
}

</style>